package com.lzc.springboot.service.impl;

import com.lzc.springboot.domain.Crop;
import com.lzc.springboot.domain.ResultInfo;
import com.lzc.springboot.mapper.CropMapper;
import com.lzc.springboot.service.CropService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CropServiceImpl implements CropService {

  @Autowired
  private CropMapper cropMapper;

  @Override
  public ResultInfo<Crop[]> findAll() {
    ResultInfo<Crop[]> info = new ResultInfo<>();
    Crop[] crops = cropMapper.findAll();
    if (crops == null || crops.length == 0){
      info.setMsg("数据库为空，请联系管理员！");
      info.setCode(2); // 2表示农作物数据读取失败
    }else {
      info.setCode(1);
    }
    info.setData(crops);
    return info;
  }
}
